<?php
require_once('../YrPHP.php');
require_once('../YrPHPEnglish.php');
header('Content-type: text/html; charset=UTF-8');

/**
 * Basic examples that shows how to use the YrPHP-class.
 * 
 * @author Hans Petter Eide
 * 
 */
	
/**
 * Example 1:
 * Retrieve temperature, precipitation and windspeed in MPS for the three following days for Oslo, Norway and
 * output the data in norwegian. The cache time is set to 3600 seconds.
 * 
 */

// Instantiate YrPHP-class
echo "EXAMPLE 1:" . "<br/>";
$yr = new YrPHP("http://www.yr.no/sted/Norge/Oslo/Oslo/Oslo/varsel.xml", "oslo.xml", 3, "", 3600);

// Get needed data
$numPeriods = $yr->getNumPeriods();
$temperatures = $yr->getTemperatures();
$precipitations = $yr->getPrecipitations();
$windSpeedMPS = $yr->getWindSpeedMps();

for ($i = 0; $i < $numPeriods; $i++){
	echo "Temperature: " . $temperatures[$i] . "\tPrecipitation: " .$precipitations[$i] . "\tWind Speed:" . $windSpeedMPS[$i] . "<br/>";
}

/**
 * Example 2:
 * Retrieve the wind direction with corresponding names and periods for the five following days for Trondheim, Norway
 */
echo "<br/>";
echo "EXAMPLE 2:" . "<br/>";
$yr->setForecastUrl("http://www.yr.no/sted/Norge/S%C3%B8r-Tr%C3%B8ndelag/Trondheim/Trondheim/varsel.xml");
$yr->setFilename("trondheim.xml");
$yr->setNumDays(5);
$yr->setXML();

$numPeriods = $yr->getNumPeriods();
$windSpeedNames = $yr->getWindSpeedNames();
$windDirections = $yr->getWindDirections();
$timeFrom = $yr->getTimeFrom();
$timeTo = $yr->getTimeTo();

for ($i = 0; $i < $numPeriods; $i++){
	echo $timeFrom[$i] . "--" . $timeTo[$i] . ": " . $yr->getWindDirectionName($windDirections[$i]) . " " .  strtolower($windSpeedNames[$i]) . "<br/>";
}



/**
 * Example 3:
 * Retrieve the wind direction with corresponding names and periods for the five following days for New York, US
 * by instantiating the class YrPHPEnglish. This class is an exstension of the class YrPHP, where the wind direction
 * names have been set to english.
 */
echo "<br/>";
echo "EXAMPLE 2:" . "<br/>";
$yrenglish = new YrPHPEnglish("http://www.yr.no/place/USA/New_York/New_York/forecast.xml", "newyork.xml", 5, "", 3600);
$numPeriods = $yrenglish->getNumPeriods();
$windSpeedNames = $yrenglish->getWindSpeedNames();
$windDirections = $yrenglish->getWindDirections();
$timeFrom = $yrenglish->getTimeFrom();
$timeTo = $yrenglish->getTimeTo();

for ($i = 0; $i < $numPeriods; $i++){
	echo $timeFrom[$i] . "--" . $timeTo[$i] . ": " . $windSpeedNames[$i] . " from the " . $yrenglish->getWindDirectionName($windDirections[$i]) . "<br/>";
}